|
|
|
| |
|
|
|
|
It is very important that you set the Startup Form to Sub Main. If you forget to do this, your code runs just fine as a standalone application, but does not accept command-line parameters and cannot run as an OLE Server object. |
|
|
|
|
|
|
|
|
|
|
That's the last routine in the SQLVBMOD code module. Save this module and save the project before you continue. In the next section, you add the code that reads an existing MDB and generates a valid SQL-Visual Basic script. |
|
|
|
|
|
|
|
|
Creating the SQLVBGEN Module |
|
|
|
|
|
|
|
|
Because you have the entire Microsoft DAO at your disposal, it is possible to read an existing MDB and generate a valid SQL-Visual Basic script that can be used to re-create the database structure. This can be done by walking through all the collections of table, index, relationship, and field objects. In this section you create the code that does just that. |
|
|
|
|
|
|
|
|
First, add a new BAS module to your project. Set its Name property to SQLVBGEN. Then add the code from Listing A.27 to the general declarations section of the module. |
|
|
|
|
|
|
|
|
Listing A.27. Coding the general declaration section of SQLVBGEN. |
|
|
|
|
|
|
|
|
Option Explicit
Dim cDBName As String
Dim cWrLine As String
Dim cWrFile As String
Dim objDB As Database
Dim nWrFile As Integer
Dim EOL As String
Dim INDENT As Integer |
|
|
|
|
|
|
|
|
These are the only module-level variables you need for this section. |
|
|
|
|
|
|
|
|
Coding the AutoGen Method |
|
|
|
|
|
|
|
|
The top-level routine (called AutoGen) is used to create the entire script. It accepts two parameters: the MDB name and the SQL script name. Add the code in Listing A.28 to your module. |
|
|
|
|
|